package org.lx.nursing.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.lx.common.annotation.Log;
import org.lx.common.core.controller.BaseController;
import org.lx.common.core.domain.AjaxResult;
import org.lx.common.core.domain.R;
import org.lx.common.core.page.TableDataInfo;
import org.lx.common.enums.BusinessType;
import org.lx.nursing.domain.NursingTask;
import org.lx.nursing.dto.NursingTaskDto;
import org.lx.nursing.service.INursingTaskService;
import org.lx.nursing.vo.NursingTaskVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing/task")
@Api(tags = "护理任务管理")
@Slf4j
public class NursingTaskController extends BaseController {
    @Autowired
    private INursingTaskService nursingTaskService;

    @GetMapping("/list")
    @ApiOperation(value = "获取护理任务列表")
    @SuppressWarnings("unchecked")
    public TableDataInfo<List<NursingTask>> list(NursingTaskDto dto) {
        startPage();
        return getDataTable(nursingTaskService.selectNursingTaskList(dto));
    }


    /**
     * 获取护理任务详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation("获取护理任务详细信息")
    public R<NursingTaskVo> getInfo(@ApiParam(value = "护理任务ID", required = true) @PathVariable("id") Long id) {
        return R.ok(nursingTaskService.selectNursingTaskById(id));
    }


    /**
     * 2.2.4 任务执行
     * 接口地址:/nursing/nursingTask/do
     * 请求方式:PUT
     */
    @PutMapping("/do")
    public AjaxResult doTask(@RequestBody NursingTaskDto dto) {
        log.info("执行任务{}", dto.toString());
        return toAjax(nursingTaskService.updateNursingTask(dto));
    }


    /**
     * 2.2.3 取消任务
     * 接口地址:/nursing/nursingTask/cancel
     * 请求方式:PUT
     */
    @PutMapping("/cancel")
    public AjaxResult cancel(@RequestBody NursingTaskDto dto) {
        log.info("取消任务{}", dto.toString());
        return toAjax(nursingTaskService.cancelTask(dto));
    }

    /**
     * 2.2.5 任务改期
     * 接口地址:/nursing/nursingTask/updateTime
     * 请求方式:PUT
     */
    @PutMapping("/updateTime")
    public AjaxResult updateTime(@RequestBody NursingTaskDto dto) {
        log.info("任务改期{}", dto.toString());
        return toAjax(nursingTaskService.updateNursingTask(dto));
    }
}
